//
//  MyFMCategotyDetailCell.m
//  悦读
//
//  Created by dllo on 15/5/23.
//  Copyright (c) 2015年 贾建兴. All rights reserved.
//

#import "MyFMCategotyDetailCell.h"
#import <UIImageView+WebCache.h>

@implementation MyFMCategotyDetailCell

- (void)dealloc
{
    [_image release];
    [_bookNameLabel release];
    [_authorLabel release];
    [_scoreLabel release];
    [_shortIntroLabel release];
    [_retentionRatioLabel release];
    [super dealloc];
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if ( self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        // 创建自定义视图中的view
        [self createView];
    }
    return self;
}


// 创建自定义视图中的view
- (void)createView
{
    self.image = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 50, 70)];
    [self addSubview:self.image];
    [self.image release];
    
    
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(self.image.frame.size.width + 20, 10, self.frame.size.width - self.image.frame.size.width -30 , 70)];
    [self addSubview:view];
    [view release];
    
    self.bookNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, view.frame.size.width, 30)];
    self.bookNameLabel.font = [UIFont systemFontOfSize:20];
    self.bookNameLabel.textColor = [UIColor grayColor];
    [view addSubview:self.bookNameLabel];
    [self.bookNameLabel release];
    
    // 简介
    self.shortIntroLabel  = [self WithFrame:CGRectMake(0, 30, view.frame.size.width, 20) superView:view];
    self.shortIntroLabel.textColor = [UIColor lightGrayColor];
    self.shortIntroLabel.font = [UIFont systemFontOfSize:13];
    [self.shortIntroLabel release];
    // 作者. 还有图标//?????
    self.authorLabel = [self WithFrame:CGRectMake(0, 55, 60, 15) superView:view];
//    self.authorLabel.backgroundColor = [UIColor blackColor];
    self.authorLabel.font = [UIFont systemFontOfSize:10];
    self.authorLabel.textColor = [UIColor grayColor];
    [self.authorLabel release];
    // 评分, 图标
    self.scoreLabel = [self WithFrame:CGRectMake(60, 55, 40, 15) superView:view];
    self.scoreLabel.font = [UIFont systemFontOfSize:10];
    self.scoreLabel.textColor = [UIColor grayColor];
    [self.scoreLabel release];
    // 留存, 图标
    self.retentionRatioLabel = [self WithFrame:CGRectMake(110, 55, 70, 15) superView:view];
    self.retentionRatioLabel.textColor = [UIColor grayColor];
    self.retentionRatioLabel.font = [UIFont systemFontOfSize:10];
    [self.retentionRatioLabel release];
    
    
}



- (void)addDataToView:(NSMutableDictionary *)dic
{


    [self.image sd_setImageWithURL:[NSURL URLWithString:[dic objectForKey:@"cover1"]] placeholderImage:[UIImage imageNamed:@"无封面.gif"]];

    self.bookNameLabel.text = [dic objectForKey:@"bookName"];
    NSString *shortIntro = [dic objectForKey:@"shortIntro"];
    if ( [shortIntro isEqualToString:@"null"] ) {
        self.shortIntroLabel.text = @"暂无简介";
        
    } else
    {
        self.shortIntroLabel.text = shortIntro;
    }
    self.authorLabel.text = [dic objectForKey:@"author"];
    // score对应的事NSNumber类型
    self.scoreLabel.text = [NSString stringWithFormat:@"评分:%@",[dic objectForKey:@"score"]];
    self.retentionRatioLabel.text = [NSString stringWithFormat:@"留存 %@", [dic objectForKey:@"retentionRatio"]];
    
}


- (UILabel *)WithFrame:(CGRect)frame superView:(UIView *)superView
{
    UILabel *label = [[UILabel alloc] initWithFrame:frame];
    [superView addSubview:label];
    return label;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
